-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Postgres: Move io to background task. #3891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
I'll be honest, seeing this posted took the wind out of my sails a bit because I was really looking forward to experimenting with this, but there's so much other work that needs to be done anyway that I'm not going to get too hung up on it. I appreciate the initiative. However, I don't have the time or energy to review this properly while trying to get 0.9.0 out the door so I think ideally we could land this in 0.9.1 or 0.9.2 since it should be backwards-compatible anyway. |
Right, I learned a lot while working on this. I mean there are many ways to solve this problem, if you'd like you can still experiment and see what solution you like best. I can imagine that this takes some effort to review and don't mind when this is released, I'll rebase when needed. |
This PR moves all the io in the postgres driver to a background task. This should fix some long standing issues with cancellation safety and unblock/allow features like query pipelining, CopyBoth mode (#2924) and the ability to cancel queries. This also simplifies the dropping of
PgTransaction
,PgCopyIn
andPgListener
. There is still some work to do to increase performance but that's out of the scope of this PR.Notable changes:
SocketExt
: An extension trait forSocket
which has async methods for reading, writing, flushing and closing.BufferedSocket
now has poll methods for reading messages.BufferedSocket
has aSink<&[u8]>
impl to send bytes.Pipe
is added; a temporary stream of responses from the background worker.Worker
is added; the background worker that handles all the io.ReadyForQuery
messages because thewait_until_ready
mechanism is removed.Shared
is added; a shared structure between the connection and background worker.This is a pretty big change that touches a lot in the postgres driver. I've added a lot of comments to explain my thinking. I'd recommend going commit by commit for reviewing. If there is anything else I can do to make this easier lmk.
Is this a breaking change?
No, this PR only has breaking changes in sqlx-core which is semver exempt. One unit test had to be changed for
PgListener
because the buffering mechanism is changed. I don't think that makes this a breaking change and I don't think Hyrum's law applies here.